package com.lzy.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.lzy.gmail.bean.UserAdress;
import com.lzy.gmail.service.UserService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

@Service(version = "1.0.0",weight = 100) // 暴露服务
@Component
public class UserServiceImpl implements UserService {

	@HystrixCommand // 代理
	@Override
	public List<UserAdress> getUserAddressList(String userId) {

//		try {
//			System.out.println("UserServiceImpl 我睡五秒钟~~new~~");
//			Thread.sleep(5000);
//		} catch (InterruptedException e) {
//			e.printStackTrace();
//		}

		System.out.println("UserServiceImpl 3");

		// 模拟出现异常
		double random = Math.random();
		System.out.println("random = " + random);
		if(random > 0.5) throw new RuntimeException();

		UserAdress userAdress1 = new UserAdress(1, "长沙", "1", "李老师", "199", "是");
		UserAdress userAdress2 = new UserAdress(2, "长沙", "2", "谭老师", "198", "是");
		return Arrays.asList(userAdress1, userAdress2);
	}
}
